package com.jin.lazytool.entity;

import com.github.kwhat.jnativehook.mouse.NativeMouseEvent;
import javafx.scene.control.Label;
import javafx.scene.control.TextField;
import javafx.scene.layout.FlowPane;
import javafx.scene.layout.Pane;

import java.awt.event.InputEvent;

public abstract class MouseClickEvent extends IEvent{

    private int button;
    private int x;
    private int y;
    private String buttonString;

    public MouseClickEvent(){}
    public MouseClickEvent(NativeMouseEvent mouseEvent){
        this.x = mouseEvent.getX();
        this.y = mouseEvent.getY();
        this.setButton(getMouseButton(mouseEvent));
    }

    public int getButton() {
        return button;
    }



    public void setButton(int button) {
        this.button = button;
        this.buttonString = getMouseButtonString();
    }

    public int getX() {
        return x;
    }

    public void setX(int x) {
        this.x = x;
    }

    public int getY() {
        return y;
    }

    public void setY(int y) {
        this.y = y;
    }


    private int getMouseButton(NativeMouseEvent mouseEvent){
        if(NativeMouseEvent.BUTTON1 == mouseEvent.getButton()){
            return InputEvent.BUTTON1_DOWN_MASK;
        }else if(NativeMouseEvent.BUTTON2 == mouseEvent.getButton()){
            return InputEvent.BUTTON2_DOWN_MASK;
        }else if(NativeMouseEvent.BUTTON3 == mouseEvent.getButton()){
            return InputEvent.BUTTON3_DOWN_MASK;
        }else {
            return InputEvent.BUTTON1_DOWN_MASK;
        }
    }

    private String getMouseButtonString(){
        if(InputEvent.BUTTON1_DOWN_MASK == button){
            return "左键";
        }else if(InputEvent.BUTTON2_DOWN_MASK == button){
            return "右键";
        }else if(InputEvent.BUTTON3_DOWN_MASK == button){
            return "中键";
        }else {
            return "?";
        }
    }
    @Override
    public Pane initDesc() {
        FlowPane pane = new FlowPane();
        pane.setStyle("-fx-pref-height: 26;");
        Label label = new Label(String.format(initDescVal() + "%s: x: ",buttonString));
        TextField fieldx = new TextField(String.valueOf(x));
        TextField fieldy = new TextField(String.valueOf(y));
        fieldx.setStyle("-fx-pref-width: 80;");
        fieldy.setStyle("-fx-pref-width: 80;");
        fieldx.setEditable(false);
        fieldy.setEditable(false);
        pane.getChildren().addAll(label,fieldx,new Label("  y:"),fieldy);
        return pane;
    }

    abstract String initDescVal();


    @Override
    public void show() {

    }
}
